//
//  YUNSubTagCell.m
//  BaiSi
//
//  Created by warm on 17/9/5.
//  Copyright © 2017年 hp. All rights reserved.
//

#import "YUNSubTagCell.h"
#import "YUNSubTagItem.h"

#import <UIImageView+WebCache.h>

@interface YUNSubTagCell()


@property (weak, nonatomic) IBOutlet UIImageView *iconVIew;
@property (weak, nonatomic) IBOutlet UILabel *nameView;

@property (weak, nonatomic) IBOutlet UILabel *numView;

@end





@implementation YUNSubTagCell

/*
 
 
 设置图片的圆角：
 方法1：IOS9以后的用法,  //设置头像圆角,在IOS9苹果修复，若在IOS9之前的IOS7、IOS8的话用图片裁剪
 
           _iconVIew.layer.cornerRadius=30;
 
               _iconVIew.layer.masksToBounds=YES;
    方法2： 裁剪图片（生成新的图片->图片上下文才能生成新的图片）

 
 
 设置数字：当数字达到一定程度的时候就将其缩率
 
 
 */


-(void)setItem:(YUNSubTagItem *)item
{


    _item=item;
    
    //设置内容
    _nameView.text=item.theme_name;
    
    //加载处理过的数字
    
    [self resolveNum];
    //方法2：裁剪图片，生成圆角图片
    
    
 
    
    [_iconVIew sd_setImageWithURL:[NSURL URLWithString:item.image_list] placeholderImage:[UIImage imageNamed:@"defaultUserIcon"] options:SDWebImageCacheMemoryOnly  completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
        
        
        //1、开启图形上下文
        
        
        UIGraphicsBeginImageContextWithOptions(image.size, NO, 0);
        
        //2、描述裁剪区域
        
        UIBezierPath *path=[UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, image.size.width, image.size.height)];
        //3、设置裁剪区域
        
        [path addClip];
        //4、画图片
        
        [image drawAtPoint:CGPointZero];
        //5、取出图片
        
        image=UIGraphicsGetImageFromCurrentImageContext();
        //6、关闭上下文
        UIGraphicsEndImageContext();
        
        _iconVIew.image=image;
        
    }];
    
    
    
  
    

}

//设置数字

-(void)resolveNum
{

    
    NSString *numStr=[NSString stringWithFormat:@"%@人订阅",_item.sub_number];
    NSInteger num=_item.sub_number.integerValue;
    
    
    if(num>10000)
    {
        
        
        CGFloat numF=num/10000.0;
        
        numStr=[NSString stringWithFormat:@"%.1f万人订阅",numF];
        numStr=[numStr stringByReplacingOccurrencesOfString:@".0" withString:@""];
        
        
    }
    
    
    _numView.text=numStr;
    




}



//从Xib中加载只会调用一次（设置图片的圆角效果）

- (void)awakeFromNib {
    //设置头像圆角,在IOS9苹果修复，若在IOS9之前的IOS7、IOS8的话用图片裁剪
    
//    _iconVIew.layer.cornerRadius=30;
 
  //  _iconVIew.layer.masksToBounds=YES;
    
    
    
    

}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
